package com.hemi.rhet.html;

import java.util.ArrayList;

public class HtmlTemplate{
	private HtmlTemplate(){
 
	}
	public static HtmlTemplate getNewInstance(){
		return new HtmlTemplate();
	}
	private boolean headAppeded = false;
	private boolean endAppeded = false;
	private StringBuffer head =new StringBuffer();
	
	private ArrayList<String> scriptUrls =new ArrayList<String>();
	//("file:///android_asset/index.html");

	
	private StringBuffer body =new StringBuffer();
	
	private StringBuffer scriptContent =new StringBuffer();
	
	public HtmlTemplate appendBody(String content){
		 this.body.append(content);
		return this;
	}
	
	public HtmlTemplate appendScriptUrl(String url){
		 this.scriptUrls.add(url);
		return this;
	}
	
	public HtmlTemplate appendScriptContent(String javascript){
		scriptContent.append(javascript);
		return this;
	}
	
	public HtmlTemplate appendHeader(String head){
			this.head.append(head);
		return this; 
	}
	private String getScript(){
		StringBuffer sb = new StringBuffer("");
		for(String str:scriptUrls)
		{
			sb.append(" <script  type='text/javascript' src='"+str+"'></script> ");
		}
		return sb.toString();
	}
	
	public String getHtml(){
		return ("<html><head>" +
					head.toString()+
				getScript()+
				"<script>" +scriptContent.toString()+
				"</script>"+
				"</head>" +
				"<body height='400' width='100%' style=\"background-color:black\">" +
					body.toString()+
				"</body></html>");
//		.replace("<", "&lt;").replace(">", "&gt;").replace("\"", "'").replace(" ","\\s") ;
	}

	
}
